<template>
	<div>
		<el-row :gutter="24">

			<el-col :span="1" style="margin-right:10px;">
				<p class="queryLabel">状态:</p>
			</el-col>
			<el-col :span="4">
				<el-select v-model="STATUSData" style="width: 100%;" placeholder="请选择" left size="small" clearable>
					<el-option v-for="item in statusCombo" :label="item.label" :value="item.value"></el-option>
				</el-select>
			</el-col>
			<el-col :span="1" style="margin-right:10px;">
				<p class="queryLabel">车牌号:</p>
			</el-col>
			<el-col :span="4">
				<el-input v-model="plateNumData" size="small" placeholder="请输入车牌号">
				</el-input>
			</el-col>

			<el-col :span="1" style="margin-right:10px;">
				<p class="queryLabel">车架号:</p>
			</el-col>
			<el-col :span="4">
				<el-input v-model="vin" size="small" placeholder="请输入车架号">
				</el-input>
			</el-col>
			<el-col :span="1" style="margin-right:10px;">
				<p class="queryLabel">电话/姓名:</p>
			</el-col>
			<el-col :span="4">
				<el-input v-model="nameOrTel" size="small" placeholder="请输入电话或姓名">
				</el-input>
			</el-col>

		</el-row>
		<el-row :gutter="24">
			<el-col :span="1" style="margin-right:10px;">
				<p class="queryLabel">开始时间:</p>
			</el-col>
			<el-col :span="4">
				<el-date-picker style="width:95%" v-model="startDate" type="date" placeholder="开始时间" size="small">
				</el-date-picker>
			</el-col>
			<el-col :span="1" style="margin-right:10px;">
				<p class="queryLabel">结束时间:</p>
			</el-col>
			<el-col :span="4">
				<el-date-picker style="width:95%" v-model="endDate" type="date" placeholder="结束时间" size="small">
				</el-date-picker>
			</el-col>


			<el-col :span="1" style="margin-right:10px;">
				<p class="queryLabel">区域:</p>
			</el-col>
			<el-col :span="4">
				<el-select size="small" style="width: 100%;" v-model="area" placeholder="请选择区域" clearable @change="getCompanyInfo">
					<el-option v-for="item in areaCombo" :label="item.label" :value="item.code"></el-option>
				</el-select>
			</el-col>
			<el-col :span="1" style="margin-right:10px;">
				<p class="queryLabel">品牌:</p>
			</el-col>
			<el-col :span="4">
				<el-select size="small" style="width: 100%;" v-model="brand" placeholder="请选择品牌名称" clearable @change="getCompanyInfo">
					<el-option v-for="item in brandCombo" :label="item.label" :value="item.code"></el-option>
				</el-select>
			</el-col>
		</el-row>
		<el-row :gutter="24">

			<el-col :span="1" style="margin-right:10px;">
				<p class="queryLabel">公司:</p>
			</el-col>
			<el-col :span="4">
				<el-select size="small" style="width: 100%;" v-model="companyId" placeholder="请选择公司名称" @change="getCompany" clearable>
					<el-option v-for="item in companyCombo" :label="item.oName" :value="item.id"></el-option>
				</el-select>
			</el-col>

			<el-col :span="1" style="margin-right:10px;">
				<p class="queryLabel">发起部门:</p>
			</el-col>
			<el-col :span="4">
				<el-select v-model="deptId" style="width: 100%;" placeholder="请选择" left size="small" clearable>
					<el-option v-for="item in deptCombo" :label="item.oName" :value="item.id"></el-option>
				</el-select>
			</el-col>
			<el-col :span="1" style="margin-right:10px;">
				<p class="queryLabel">创建人员:</p>
			</el-col>
			<el-col :span="4">
				<el-select v-model="saId" placeholder="请选择" style="width: 100%;" left size="small" clearable>
					<el-option v-for="item in lengthComboData" :label="item.label" :value="item.value"></el-option>
				</el-select>
			</el-col>
			<el-col :span="1" style="margin-right:10px;">
				<p class="queryLabel">活动:</p>
			</el-col>
			<el-col :span="4">
				<el-select v-model="activeCheck" filterable style="width: 100%;" left size="small" placeholder="请选择活动" clearable>
					<el-option v-for="item in queryNameCombo" :label="item.label" :value="item.value"></el-option>
				</el-select>
			</el-col>
			<el-col :span="2" style="margin-left: ;text-align: center;">
				<el-button type="primary" size="small" v-on:click='couponQuery'>查 询</el-button>
			</el-col>

		</el-row>

		<el-row :gutter="24">

			<el-col :span="24" style="text-align: right;float:right">
				<el-button type="primary" size="small" v-on:click='couponAdd' v-if="btnGroup.add">新增</el-button>
				<el-button type="primary" size="small" v-on:click='pass(1)'>提交</el-button>
				<el-button type="primary" size="small" v-on:click='Export' v-if="btnGroup.export">导出优惠券</el-button>
				<el-button type="primary" size="small" v-on:click='ExportActivity' v-if="btnGroup.export">导出活动</el-button>
				<el-button type="primary" size="small" v-on:click='msgDelete' v-if="btnGroup.del">删除</el-button>
				<el-button type="primary" size="small" v-on:click='msgPrint' v-if="btnGroup.print">打印</el-button>

			</el-col>
		</el-row>

		<el-row>
			<el-col :span="24">
				<el-table :data="tableData.dataList" stripe border v-loading="loading" @selection-change="handleSelectionChange">
					<el-table-column type="selection" width="60" fixed>
					</el-table-column>
					<el-table-column prop="num" label="优惠券号" align="right" width="250"></el-table-column>
					<el-table-column prop="name" label="所属活动" width="200"></el-table-column>
					<el-table-column prop="couponType" label="优惠券类型" width="120" :formatter="couponCov"></el-table-column>
					<el-table-column prop="deptName" label="发起部门" width="200"></el-table-column>
					<el-table-column prop="shbz" label="审批进度" width="200"></el-table-column>
					<el-table-column prop="createUser" label="创建人员" width="200"></el-table-column>
					<el-table-column prop="saler" label="销售人员" width="200"></el-table-column>
					<el-table-column prop="createTime" label="创建时间" width="200" :formatter="timeFormate2"></el-table-column>
					<el-table-column prop="gift" label="礼品名称" width="200"></el-table-column>
					<el-table-column prop="remainder" label="剩余金额" width="120"></el-table-column>
					<el-table-column prop="youxiaoqi" align="center" label="有效期" :formatter="timeFormates" width="150"></el-table-column>
					<el-table-column prop="plateNum" label="车牌号" width="150"></el-table-column>
					<el-table-column prop="contactName" label="车主姓名" width="200"></el-table-column>
					<el-table-column prop="contactPhone" align="right" label="联系电话" width="150"></el-table-column>
					<el-table-column prop="useDate" align="center" label="使用时间" :formatter="timeFormate" width="200"></el-table-column>
					<el-table-column prop="dayinDate" align="center" label="打印时间" :formatter="dytimeFormate" width="200"></el-table-column>
					<el-table-column prop="gongdanId" label="关联工单号" width="200"></el-table-column>
					<el-table-column prop="status" label="使用状态" :formatter="levelCov" width="150"></el-table-column>

					<el-table-column label="操作" align="right" width="100">
						<template scope="scope">
							<el-button type="primary" size="mini" @click.native.prevent="info(scope.$index)">明细</el-button>
						</template>
					</el-table-column>
					<!--<el-table-column label="操作" width="120" fixed="right">
								<template scope="scope">
									<el-tooltip class="item" effect="light" v-if="btnGroup.del" content="删除" placement="top">
										<el-button type="danger" size="mini" icon="delete" @click.native.prevent="msgDelete(scope.$index)"></el-button>
									</el-tooltip>
									<el-tooltip class="item" v-if="scope.row.status == '0' && btnGroup.print" effect="light" content="打印" placement="top">
										<el-button type="primary" size="mini" @click.native.prevent="msgPrint(scope.$index)">打印</el-button>
									</el-tooltip>
								</template>
							</el-table-column>-->
				</el-table>
				<el-pagination small @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="CurentPage" :page-sizes="page.pageSizes" :page-size="page.pageSize" layout=" total,prev, pager, next" :total="tableData.total">
				</el-pagination>
			</el-col>
		</el-row>

		<!--
																																																																																																																																																																																																																									        	作者：1040117458@qq.com
																																																																																																																																																																																																																									        	时间：2017-03-07
																																																																																																																																																																																																																									        	描述：新增界面
																																																																																																																																																																																																																									        -->
		<el-dialog tittl="优惠券生成" v-model="couponFormShow">

			<el-select v-model="couActive" filterable left size="small" placeholder="请选择活动" clearable @change="couponChange">
				<el-option v-for="item in nameCombo" :label="item.label" :value="item.value"></el-option>
			</el-select>

			<el-form :model="couponFormData" ref="couponForms" :rules="couponRule" label-width="100px" v-if="fromShow">
				<el-row :gutter="24">
					<el-col :span="12">
						<el-form-item label="所属活动:" prop="name">
							{{couponFormData.name}}
						</el-form-item>
					</el-col>

					<el-col :span="12">
						<el-form-item label="礼品名称:" prop="gift">
							{{couponFormData.gift}}
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="礼品价值:" prop="cost">
							{{couponFormData.cost}}
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="单车发券数量:" prop="couCount">
							{{couponFormData.couCount}}
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="车牌号:" prop="plateNum" required>
							<el-input size="small" v-model="couponFormData.plateNum" style="width:200px;">
							</el-input>
							<el-button type="primary" size="small" v-on:click='plateNumChange'>搜索</el-button>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="车辆VIN:" prop="vin" required>
							<el-input size="small" v-model="couponFormData.vin" style="width:200px;">
							</el-input>
						</el-form-item>
					</el-col>

					<el-col :span="12">
						<el-form-item label="车主姓名:" prop="ownerName">
							<el-input size="small" v-model="couponFormData.ownerName" style="width:200px;">
							</el-input>
						</el-form-item>
					</el-col>

					<el-col :span="12">
						<el-form-item label="联系电话:" prop="ownerTel">
							<el-input size="small" v-model="couponFormData.ownerTel" style="width:200px;">
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="销售人员:" prop="saler">
							<el-input size="small" v-model="couponFormData.saler" style="width:200px;">
							</el-input>
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="使用规则:" prop="message">
							{{couponFormData.message}}
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item>
							<qrcode :background="qr.background" :size="qr.size" :value="qr.value"></qrcode>
						</el-form-item>
					</el-col>

					<el-col :span="24">
						<el-form-item prop="num">
							{{couponFormData.oShortName}}优惠劵号码： {{couponFormData.num}}
						</el-form-item>
					</el-col>
					<el-col :span="24">
						<el-form-item label="地址:" prop="contactPhone">
							{{couponFormData.city}}{{couponFormData.oAddress}}{{couponFormData.oName}}
							<br>预约及二十四小时救援电话：{{couponFormData.oPhone}}
							<br>敬请提前一天预约专属客户经理，省时，省心， 方便，快捷
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="savecoupon" :disabled="saveBtnDis" id="saveBtn">保存</el-button>
			</div>
		</el-dialog>
		<!--
																																																																																																																																																																																																																										        	作者：1040117458@qq.com
																																																																																																																																																																																																																										        	时间：2017-03-09
																																																																																																																																																																																																																										        	描述：打印界面
																																																																																																																																																																																																																										        -->
		<el-dialog tittl="打印" v-model="dayinFormShow" id="dvData">
			<div id="printHtml">
				<div v-for="(item,index) in dayinData">
					<!--
                    	作者：1040117458@qq.com
                    	时间：2017-08-06
                    	描述：index%2==0不分页
                    -->
					<div v-if="index%2 == 0">
						<div style="height:300px ;">
							<el-row style="padding-left:5px; width:800px">
								<el-col :span="24">
									<div style="float:left;display:block">

										<div style="height:280px;width:440px;float:left;border:0px solid RED">
											<p>
												<b>
										<span>{{item.num}}</span>
									</b>
											</p>
											<p>
												<b>赠品：</b>
												<span>{{item.gift}}</span>
											</p>
											<p>
												<b>所属活动：</b>
												<span>{{item.name}}</span>
											</p>
											<p>
												<b>发起部门：</b>
												<span>{{item.deptName}}</span>
											</p>
											<p>
												<b>发券日期：</b>
												<span>{{item.createDate}}</span>
											</p>
											<p>
												<b>截止日期：</b>
												<span>{{item.youxiaoqi}}</span>
											</p>
											<p>
												<b>{{item.oName}}&nbsp;电话:</b>{{item.oPhone}}
											</p>
											<p>
												<b>{{item.city}}{{item.oAddress}} </b>
											</p>
										</div>
										<div style="height:240px;width:230px;float:right;margin-top:5px;margin-left:5px;margin-bottom:5px">
											<!--二维码 开始-->
											<qrcode :background="qr.background" style="height:220px;width:230px" :id="item.num" :size="qr.size" :value="item.num"></qrcode>
											<!--二维码  结束-->
										</div>
									</div>
								</el-col>
							</el-row>

						</div>
						<!--车牌号信息 开始-->
						<el-row style="padding-left:5px; margin-top:5px">
							<el-col :span="24">
								<div>
									<table width="100%" border="1px solid #F9FAFC" cellspacing="0px" cellpadding="10px" bgcolor="#F9FAFC" style="border-collapse:collapse;font-size: 10px;margin:0 auto;color:#1F2D3D">
										<tr>
											<td width="150">
												<b>车牌号</b>
											</td>
											<td width="150">
												<b>车辆VIN</b>
											</td>
											<td>
												<b>联系人</b>
											</td>
											<td>
												<b>手机</b>
											</td>
										</tr>
										<tr>
											<td>{{item.plateNum}}</td>
											<td>{{item.vin}}</td>
											<td>{{item.contactName}}</td>
											<td>{{item.contactPhone}}</td>
										</tr>
									</table>
								</div>
							</el-col>
						</el-row>
						<!--车牌号信息 结束-->
						<!--底部的注意  开始-->
						<el-row :gutter="24">
							<el-col :span="24">
								<p style="height: 30px;">
									<b style="float: left;">客户签字：</b>
									<b style="float: right;">(本优惠劵盖章有效)</b>
								</p>
							</el-col>
						</el-row>
						<el-row>
							<el-col :span="24" style="margin-top:15px">
								<div style="width:100%;">
									<p style="border:1px solid #ddd;padding:5px 5px;">
										<b>注意：</b> {{item.message}}
									</p>
								</div>
							</el-col>
						</el-row>
						<div style="height: 15px;"></div>
						<hr style="width: 100%;height:0px;border-bottom: #000 2px dashed;"></hr>
						<div style="height: 15px;"></div>
					</div>
					<!--
                    	作者：1040117458@qq.com
                    	时间：2017-08-06
                    	描述：index%2==1分页
                    -->
					<div v-if="index%2 == 1" style="page-break-after:always">
						<div style="height:300px ;">
							<el-row style="padding-left:5px; width:800px">
								<el-col :span="24">
									<div style="float:left;display:block">

										<div style="height:280px;width:440px;float:left;border:0px solid RED">
											<p>
												<b>
										<span>{{item.num}}</span>
									</b>
											</p>
											<p>
												<b>赠品：</b>
												<span>{{item.gift}}</span>
											</p>
											<p>
												<b>所属活动：</b>
												<span>{{item.name}}</span>
											</p>
											<p>
												<b>发起部门：</b>
												<span>{{item.deptName}}</span>
											</p>
											<p>
												<b>发券日期：</b>
												<span>{{item.createDate}}</span>
											</p>
											<p>
												<b>截止日期：</b>
												<span>{{item.youxiaoqi}}</span>
											</p>
											<p>
												<b>{{item.oName}}&nbsp;电话:</b>{{item.oPhone}}
											</p>
											<p>
												<b>{{item.city}}{{item.oAddress}} </b>
											</p>
										</div>
										<div style="height:240px;width:230px;float:right;margin-top:5px;margin-left:5px;margin-bottom:5px">
											<!--二维码 开始-->
											<qrcode :background="qr.background" style="height:220px;width:230px" :id="item.num" :size="qr.size" :value="item.num"></qrcode>
											<!--二维码  结束-->
										</div>
									</div>
								</el-col>
							</el-row>
						</div>
						<!--车牌号信息 开始-->
						<el-row style="padding-left:5px; margin-top:5px">
							<el-col :span="24">
								<div>
									<table width="100%" border="1px solid #F9FAFC" cellspacing="0px" cellpadding="10px" bgcolor="#F9FAFC" style="border-collapse:collapse;font-size: 10px;margin:0 auto;color:#1F2D3D">
										<tr>
											<td width="150">
												<b>车牌号</b>
											</td>
											<td width="150">
												<b>车辆VIN</b>
											</td>
											<td>
												<b>联系人</b>
											</td>
											<td>
												<b>手机</b>
											</td>
										</tr>
										<tr>
											<td>{{item.plateNum}}</td>
											<td>{{item.vin}}</td>
											<td>{{item.contactName}}</td>
											<td>{{item.contactPhone}}</td>
										</tr>
									</table>
								</div>
							</el-col>
						</el-row>
						<!--车牌号信息 结束-->
						<!--底部的注意  开始-->
						<el-row :gutter="24">
							<el-col :span="24">
								<p style="height: 30px;">
									<b style="float: left;">客户签字：</b>
									<b style="float: right;">(本优惠劵盖章有效)</b>
								</p>
							</el-col>
						</el-row>
						<el-row>
							<el-col :span="24" style="margin-top:15px">
								<div style="width:100%">
									<p style="border:1px solid #ddd;padding:5px 5px;">
										<b>注意：</b> {{item.message}}
									</p>
								</div>
							</el-col>
						</el-row>
					</div>
				</div>
			</div>
			<!--底部的注意 结束-->
			<el-row style="margin-left:5px">
				<el-col>
					<el-button type="primary" @click="saveDayin">点击打印</el-button>
				</el-col>
			</el-row>
		</el-dialog>

		<el-dialog tittl="审批明细" v-model="DialogApprovalDetailsShow">
			<el-row>
				<el-col :span="24">
					<el-table :data="ApprovalDetailsList" stripe border style="width: 100%">
						<el-table-column prop="approvalDate" label="审核时间" width="200"></el-table-column>
						<el-table-column prop="approvalStatus" label="审核状态" width="200" :formatter="approvalStatusCov"></el-table-column>
						<el-table-column prop="approvalers" label="审核人员" width="200"></el-table-column>
						<el-table-column prop="approvalOpinion" label="审核意见" width="200"></el-table-column>
					</el-table>
					<el-button @click="DialogApprovalDetailsShow = false" type="primary" style="float: right;">关闭</el-button>

				</el-col>
			</el-row>
		</el-dialog>

	</div>
</template>
<script>
	//二维码
	import Qrcode from 'v-qrcode/src/index'
	//时间解析

	export default {
		data: function() {
			return {
				//表格等待框
				loading: false,
				//查询条件
				area: '',
				brand: '',
				companyId: '',
				areaCombo: [],
				brandCombo: [],
				companyCombo: [],
				deptId: '', //bumenId
				//销售人员
				saler: "",
				//审批详情dialog
				DialogApprovalDetailsShow: false,
				//审批详情dialog内部数据
				ApprovalDetailsList: [],
				//打印数据（数组）
				dayinData: [],
				//人员ID
				saId: "",
				//人员list
				lengthComboData: [],
				deptCombo: [],
				companyNameList: [],
				//二维码
				qr: {
					value: '',
					size: 200,
					background: '#FFF'

				},
				//优惠券号
				num: '',
				//活动ID
				aid: '',
				fromShow: false,
				//新增优惠券界面显示
				couponFormShow: false,
				couponFormShow2: false,
				//打印界面显示
				dayinFormShow: false,
				CurentPage: 1,
				page: this.page,
				levelConvertData: {},
				//时间查询条件
				// 保存按钮-是否禁用
				saveBtnDis: false,
				//车牌号查询条件
				plateNumData: '',
				vin: '',
				nameOrTel: '',
				//活动名称查询条件
				activeCheck: '',
				// 发券
				couActive: '',
				//状态查询条件
				STATUSData: '',
				//省份简称
				shengfenCombo: [],
				//大写字母
				zimuCombo: [],
				//活动名称数据
				nameCombo: [],
				queryNameCombo: [],
				//状态数据
				statusCombo: [],
				//分组数据
				tableData: {
					total: 0,
					dataList: []
				},
				//打印
				dayinData: {
					total: 0,
					data: []
				},

				activityId: '',
				status: '',
				plateNum: '',
				startDate: '',
				endDate: '',
				shengfen: '',
				zimu: '',
				houNum: '',
				numFormData: {
					zimu: '',
					shengfen: '',
				},
				//优惠券初始
				emptFormData: {
					id: '',
					name: '',
					useDate: '',
					dayinDate: '',
					num: '',
					remart: '',
					status: '',
					gongdanId: '',
					usercarId: '',
					activityId: '',
					comboId: '',
					createDate: '',
					chanzhi: '',
					youxiaoqi: '',
					useRemark: '',
					caozuoName: '',
					dayinName: '',
					dayinDate: '',
					vin: '',
					matchOrdernum: '',
					matchAmount: '',
					plateNum: '',
					ownerName: '',
					ownerTel: '',
					contactName: '',
					contactPhone: '',
					gift: '',
					cost: '',
					message: '',
					city: '',
					oAddress: '',
					oName: '',
					oPhone: '',
					oShortName: '',
					couCountL: '', //youhuiquan shuliang
					saler: '',
				},
				//优惠券表单数据
				couponFormData: {
					id: '',
					name: '',
					useDate: '',
					dayinDate: '',
					num: '',
					remart: '',
					status: '',
					gongdanId: '',
					usercarId: '',
					activityId: '',
					comboId: '',
					createDate: '',
					chanzhi: '',
					youxiaoqi: '',
					useRemark: '',
					caozuoName: '',
					dayinName: '',
					dayinDate: '',
					vin: '',
					matchOrdernum: '',
					matchAmount: '',
					plateNum: '',
					ownerName: '',
					ownerPhone: '',
					contactName: '',
					contactPhone: '',
					gift: '',
					cost: '',
					message: '',
					city: '',
					oAddress: '',
					oName: '',
					oPhone: '',
					oShortName: '',
					couCountL: '', //youhuiquan shuliang
					saler: '',
				},
				data: {
					id: "",
					type: "T_CRM_CAR_COUPON",
				},
				couponRule: {
					ownerName: [{
						required: true,
						message: '请填写车主姓名',
						trigger: 'blur'
					}],
					ownerTel: [{
						required: true,
						message: '请填写联系电话',
						trigger: 'blur'
					}],
				},
				activityID: '',
				id: '',
				nowDate: '',
				btnGroup: {},
				multipleSelection: [],
				//审批信息
				approvalData: {
					approvalData: {
						billId: "",
						approvalOpinion: "",
						approvalStatus: "",
					},
					ids: [],
				},

			}
		},
		methods: {
			//表格中优惠券类型
			couponCov: function(row) {
				if(row.couponType == '1') {
					return "储值卡";
				} else {
					return "优惠券";
				}
			},
			//审核
			pass: function(type) {
				
				debugger;
				
				if(this.$data.multipleSelection.length > 0) {
					for(var i = 0; i < this.$data.multipleSelection.length; i++) {
						this.$data.approvalData.ids[i] = this.$data.multipleSelection[i].id;
					}
					debugger;
					this.$http.post(this.API_ROOT + '/crm/coupon/updateApprovalStatus', this.$data.approvalData, {
						params: {
							//id: this.$data.multipleSelection[0].id,
							status: type
						}
					}).then((response) => {
						if(response.data.success) {
							debugger;
							this.$data.yewuShow = false;
							this.$message(response.data.msg);
							this.$data.approvalData.ids = [];
							this.$data.multipleSelection = [];
							this.couponQuery();
						} else {
							debugger;
							this.$data.approvalData.ids = [];
							this.$data.multipleSelection = [];
							this.$message.error(response.data.msg);
						}
					}, (response) => {});
				} else {
					this.$message.error("请选择一条数据");
				}
			},

			//获取发起部门
			getCompany: function() {
				this.$data.activeCheck = "";
				this.$data.deptId = "";
				this.getPeople();//获取创建人员
				this.getactivity();//获取活动
				this.$http.get(this.API_ROOT + '/rbac/dept/org', {
					params: {
						pId: this.$data.companyId,
					}
				}).then((response) => {
					this.$data.deptCombo = response.data.dataList;
					//this.$data.levelConvertData = response.data;
				}, (response) => {});
			},

			//选择框
			handleSelectionChange: function(val) {
				debugger;
				this.$data.multipleSelection = val;
				//			if (this.$data.multipleSelection.length > 1)
				//				this.$message.error("请选择一条数据！");
			},
			saveShengfen: function() {
				this.$data.numFormData.shengfen = this.$data.shengfen;
			},
			saveZimu: function() {
				this.$data.numFormData.zimu = this.$data.zimu;
			},
			//导出按钮
			Export: function() {
				var date1 = this.$data.startDate;
				if(date1 == null || date1 == '') {
					this.$data.startDate = '';
				} else {
					//转换成long型
					this.$data.startDate = new Date(date1).getTime();
				};
				var date2 = this.$data.endDate;
				if(date2 == null || date2 == '') {
					this.$data.endDate = '';
				} else {
					this.$data.endDate = new Date(date2).getTime();
				};
				window.location.href = this.API_ROOT + '/crm/coupon/excel/exportCoupon?uid=' + window.localStorage.getItem("uid") + "&&companyId=" + this.$data.companyId +
				"&&activityId="+ this.$data.activeCheck+
								"&&status="+ this.$data.STATUSData+
								"&&plateNum="+ this.$data.plateNumData+
								"&&startDate="+ this.$data.startDate+
								"&&endDate="+ this.$data.endDate+
								"&&createUser="+ this.$data.saId+
								"&&vin="+ this.$data.vin+
								"&&nameOrTel="+ this.$data.nameOrTel+
								"&&deptId="+ this.$data.deptId+
								"&&area="+ this.$data.area+
								"&&brand="+ this.$data.brand;
			},
			
			//导出按钮
			ExportActivity: function() {
				var date1 = this.$data.startDate;
				if(date1 == null || date1 == '') {
					this.$data.startDate = '';
				} else {
					//转换成long型
					this.$data.startDate = new Date(date1).getTime();
				};
				var date2 = this.$data.endDate;
				if(date2 == null || date2 == '') {
					this.$data.endDate = '';
				} else {
					this.$data.endDate = new Date(date2).getTime();
				};
				window.location.href = this.API_ROOT + '/crm/coupon/excel/exportActivity?uid=' + window.localStorage.getItem("uid") + "&&companyId=" + this.$data.companyId +
				"&&activityId="+ this.$data.activeCheck+
								"&&status="+ this.$data.STATUSData+
								"&&plateNum="+ this.$data.plateNumData+
								"&&startDate="+ this.$data.startDate+
								"&&endDate="+ this.$data.endDate+
								"&&createUser="+ this.$data.saId+
								"&&vin="+ this.$data.vin+
								"&&nameOrTel="+ this.$data.nameOrTel+
								"&&deptId="+ this.$data.deptId+
								"&&area="+ this.$data.area+
								"&&brand="+ this.$data.brand;
			},
			
			//列表分页大小切换
			handleSizeChange: function() {},
			//列表当前页切换
			handleCurrentChange: function(currentPage) {
				this.$data.CurentPage = currentPage;
				this.couponQuery();
			},
			//使用状态解析
			levelCov: function(row, column) {
				return this.$data.levelConvertData[row.status];
			},
			levelCovert: function() {
				this.$http.get(this.API_ROOT + '/base/dict/convert', {
					params: {
						group: "030101"
					}
				}).then((response) => {
					this.$data.levelConvertData = response.data;
				}, (response) => {});
			},
			//审批状态转换
			approvalStatusCov: function(row) {
				var temp = "";
				switch(row.approvalStatus) {
					case "0":
						temp = "未通过";
						break;

					case "1":
						temp = "已通过";
						break;

					default:
						temp = "null";
						break;
				}
				return temp;
			},
			//创建时间解析
			timeFormate2: function(row, column) {
				if(row.createTime == "" || row.createTime == null) return "";
				return this.moment(Number(row.createTime)).format("YYYY-MM-DD HH:mm:ss");
			},
			//使用时间解析
			timeFormate: function(row, column) {
				if(row.useDate == "" || row.useDate == null) return "";
				return this.moment(Number(row.useDate)).format("YYYY-MM-DD HH:mm:ss");
			},
			//打印时间解析
			dytimeFormate: function(row, column) {
				if(row.dayinDate == "" || row.dayinDate == null) return "";
				return this.moment(Number(row.dayinDate)).format("YYYY-MM-DD HH:mm:ss");
			},
			//有效期解析
			timeFormates: function(row, column) {
				if(row.youxiaoqi == "" || row.youxiaoqi == null) return "";
				return this.moment(Number(row.youxiaoqi)).format("YYYY-MM-DD");
			},
			//搜索
			couponQuery: function() {

				var date1 = this.$data.startDate;
				if(date1 == null || date1 == '') {
					this.$data.startDate = '';
				} else {
					//转换成long型
					this.$data.startDate = new Date(date1).getTime();
				};
				var date2 = this.$data.endDate;
				if(date2 == null || date2 == '') {
					this.$data.endDate = '';
				} else {
					this.$data.endDate = new Date(date2).getTime();
				};
				if(this.$data.companyId == "") {
					this.$message.error("请选择公司！")
				} else {
					this.$data.loading = true;
					debugger;
					this.$http({
							method: 'POST',
							url: this.API_ROOT + '/crm/coupon/page', //url
							params: { //发送的参数
								start: this.$data.CurentPage, //页码
								limit: this.$data.page.pageSize, //每页的数量
								activityId: this.$data.activeCheck,
								status: this.$data.STATUSData,
								plateNum: this.$data.plateNumData,
								startDate: this.$data.startDate,
								endDate: this.$data.endDate,
								companyId: this.$data.companyId,
								createUser: this.$data.saId,
								vin: this.$data.vin,
								nameOrTel: this.$data.nameOrTel,
								deptId: this.$data.deptId,
								area: this.$data.area,
								brand: this.$data.brand,
							}
						})
						.then(function(resp) {

							resp.data.total = parseInt(resp.data.total);
							//es5新写法
							this.$data.tableData = resp.data;
							this.$data.loading = false;
						}, function(error) {
							//error
						})
				}

			},
			//查询
			couponAddQuery: function(val) {
				this.$data.activityID = val;
				this.$http({
						method: 'POST',
						url: this.API_ROOT + '/crm/coupon/activityInfo', //url
						params: { //发送的参数
							id: val,
						}
					})
					.then(function(resp) {
						this.$data.couponFormData = Object.assign(this.$data.couponFormData, resp.data.data);

					}, function(error) {
						//error
					})

			},
			//新增
			couponAdd: function() {
				this.$data.couActive = null;
				this.$data.fromShow = false;
				this.$data.couponFormData = Object.assign(this.$data.couponFormData, this.$data.emptFormData);
				this.$data.couponFormShow = true;
				document.getElementById("saveBtn").disabled = false;
				this.$data.saveBtnDis = false;
				this.$data.shengfen = this.$data.numFormData.shengfen;
				this.$data.zimu = this.$data.numFormData.zimu;
				this.$data.houNum = '';

			},

			//车牌号搜索事件
			plateNumChange: function() {
				debugger;
				this.$http({
					method: 'POST',
					url: this.API_ROOT + '/crm/coupon/carCouponInfo',
					params: {
						plateNum: this.$data.couponFormData.plateNum,
					}
				}).then(function(resp) {
					this.$data.couponFormData = Object.assign(this.$data.couponFormData, resp.data.data);
				}, function(error) {
					//error
				})
			},

			//优惠券保存
			savecoupon: function() {
				//this.$data.couponFormData.plateNum = this.$data.shengfen + this.$data.zimu + this.$data.houNum;
				if(this.$data.couponFormData.plateNum == '' && this.$data.couponFormData.vin == '') {
					this.$message("请填写车牌号或vin")
				} else {
					document.getElementById("saveBtn").disabled = true;
					this.$data.saveBtnDis = true;
					if(!this.$refs.couponForms) {
						document.getElementById("saveBtn").disabled = false;
						this.$data.saveBtnDis = false;
						return;
					}
					debugger;
					this.$data.couponFormData.contactName = this.$data.couponFormData.ownerName;
					this.$data.couponFormData.contactPhone = this.$data.couponFormData.ownerTel;
					this.$refs.couponForms.validate(function(valid) {
						if(valid) {
							this.$http.post(this.API_ROOT + '/crm/coupon/save', this.$data.couponFormData, {
								params: {
									aid: this.$data.activityID,
								}
							}).then(resp => {
								if(resp.data.success) {
									this.$data.couponFormShow = false;
									this.$message(resp.data.msg);
									this.couponQuery();
								} else {
									this.$message.error(resp.data.msg);
								}
							}, resp => {
								this.$data.saveBtnDis = false;
								document.getElementById("saveBtn").disabled = false;
							});
						} else {
							document.getElementById("saveBtn").disabled = false;
							this.$data.saveBtnDis = false;
						}
						return false;
					}.bind(this));
				}
			},
			couponChange: function(val) {
				debugger;
				if(val != null) {

					var Num = "";
					var timestamp = Date.parse(new Date());
					var timeDate = new Date();
					timeDate = this.moment(timeDate).format("YYYYMMDDhhmmss");
					for(var i = 0; i < 6; i++) {
						Num += Math.floor(Math.random() * 10);
						var d = new Date();
						var year = d.getFullYear();
						var month = d.getMonth() + 1; // 记得当前月是要+1的
						var dt = d.getDate();
						this.$data.nowDate = year + "年" + month + "月" + dt + "日";
					}
					this.$data.couponFormData.num = timeDate + Num;
					this.$data.qr.value = this.$data.couponFormData.num;
					//				console.log(timestamp + Num);
					this.$data.fromShow = true;
					this.couponAddQuery(val);
				}
			},
			//导出
			couponOut: function() {

			},
			//删除
			msgDelete: function(index) {
				if(this.$data.multipleSelection.length == 1) {

					var resRoleData = this.$data.multipleSelection[0];

					this.$confirm('确认要删除这条优惠券吗?', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						type: 'warning'
					}).then(() => {

						this.$http({
							method: 'GET',
							url: this.API_ROOT + '/crm/coupon/del',
							params: {
								id: resRoleData.id,
							}
						}).then(function(resp) {
							if(resp.data.success) {
								this.$message(resp.data.msg);
								this.couponQuery();
							} else {
								this.$message.error(resp.data.msg)
							}
						}, function(error) {

						})
					}).catch(() => {
						this.$message({
							type: 'info',
							message: '已取消删除'
						});
					});
				} else {
					this.$message.error("请选择一条数据");
				}
			},
			//审批明细查询
			info: function(index) {
				this.$data.data.id = this.$data.tableData.dataList[index].id;
				this.$http.post(this.API_ROOT + '/crm/crmapprovalDetail/page', this.$data.data, { //tableData.dataList
					params: {}
				}).then(resp => {
					if(resp.data.success) {
						this.$data.ApprovalDetailsList = resp.data.dataList;
						this.$data.DialogApprovalDetailsShow = true;
					}

				}, resp => {});

				debugger;
				//this.$message("已生成出库单");
			},
			//打印
			msgPrint: function(index) {
				if(this.$data.multipleSelection.length > 0) {
					debugger;

					var resRoleData = this.$data.multipleSelection;
					var hehe = 0;
					//判断所选优惠券是否都可打印
					for(var i = 0; i < resRoleData.length; i++) {
						if(resRoleData[i].status != 0) {
							hehe = 1;
							break;
						}
						if(resRoleData[i].shbz != "审核通过") {
							hehe = 1;
							break;
						}
					}
					if(hehe == 0) {

						debugger;
						this.$http({
							method: 'POST',
							url: this.API_ROOT + '/crm/coupon/couponInfo',
							body: this.$data.multipleSelection,
							params: {
								//							id: resRoleData.id,
								//							aid: resRoleData.activityId,
							}
						}).then((response) => {
							debugger;
							//返回数组
							this.$data.dayinData = response.data.dataList;
							//创建日期，有效期格式化。
							for(var j = 0; j < this.$data.dayinData.length; j++) {
								this.$data.dayinData[j].createDate = this.moment(this.$data.dayinData[j].createDate).format("YYYY-MM-DD");
								this.$data.dayinData[j].youxiaoqi = this.moment(this.$data.dayinData[j].youxiaoqi).format("YYYY-MM-DD");
							}
							//						response.data.data.createDate = this.moment(response.data.data.createDate).format("YYYY-MM-DD");
							//						response.data.data.youxiaoqi = this.moment(response.data.data.youxiaoqi).format("YYYY-MM-DD");
							//						this.$data.couponFormData = Object.assign(this.$data.couponFormData, response.data.data);
							this.$data.dayinFormShow = true;
							//						this.$data.qr.value = this.$data.couponFormData.num;

						}, (response) => {});
					} else {
						this.$message("所选优惠券必须是未打印并且已审核通过才可进行打印！")
					}
				} else {
					this.$message.error("请选择一条数据");
				}
			},

			saveDayin: function() {
				debugger;

				/*调用打印接口*/
				//用 JavaScript 实现页面数据的打印 ： 主要是用到了一个 print() 函数 ， 该函数将会打印整个 web 页面 body 内的所有 html 数据 ! 使用方法为 window.print(); 打印页面上局部的数据，则可以 用
				//把数据嵌套在 一个 div 里，获得 div
				for(var i = 0; i < this.$data.dayinData.length; i++) {
					var id = this.$data.dayinData[i].num;
					var canvans = document.getElementById(id).childNodes[0];
					var img = canvans.toDataURL("image" + i + "/png");
					document.getElementById(id).innerHTML = '<img  style="height:240px;width:250px;" src="' + img + '"/>';
					var newstr = document.getElementById("printHtml").innerHTML;

				}
				var printWindow = window.open();
				printWindow.document.body.innerHTML = newstr;
				printWindow.print();
				printWindow.close();
				for(var i = 0; i < this.$data.dayinData.length; i++) {

					// 关闭打印窗口
					var newImag = document.getElementById(id).childNodes[0];
					document.getElementById(id).innerHTML = '<canvas width="200" height="200"></canvas>';
					canvans = document.getElementById(id).childNodes[0];
					canvans.getContext("2d").drawImage(newImag, 0, 0);
				}
				//				var canvans = document.getElementById("qrcode").childNodes[0];
				//				var img = canvans.toDataURL("image/png");
				//				document.getElementById("qrcode").innerHTML = '<img  style="height:240px;width:250px;" src="' + img + '"/>';
				//				var newstr = document.getElementById("printHtml").innerHTML;
				//				var printWindow = window.open();
				//				printWindow.document.body.innerHTML = newstr;
				//				printWindow.print();
				//				printWindow.close();
				//				// 关闭打印窗口
				//				var newImag = document.getElementById("qrcode").childNodes[0];
				//				document.getElementById("qrcode").innerHTML = '<canvas width="200" height="200"></canvas>';
				//				canvans = document.getElementById("qrcode").childNodes[0];
				//				canvans.getContext("2d").drawImage(newImag, 0, 0);

				this.$data.dayinFormShow = false;
				this.$http({
					method: 'POST',
					url: this.API_ROOT + '/crm/coupon/dayin',
					body: this.$data.dayinData,
					params: {
						//					num: this.$data.couponFormData.num,
						//					aid: this.$data.couponFormData.activityId,
						//					id: this.$data.couponFormData.id,
						//					youxiaoqi: new Date(this.$data.couponFormData.youxiaoqi).getTime()
					}
				}).then(function(resp) {
					if(resp.data.success) {
						this.$message(resp.data.msg);
						this.$data.dayinFormShow = false;
						this.$data.dayinData = [];
						this.couponQuery();
					} else {
						this.$message.error(resp.data.msg)
					}
				}, function(error) {

				})

			},
			//获取公司信息
			getCompanyInfo: function() {
				//this.$data.data.companyId = ""; //清空单位
//				this.$data.companyId = ""; //清空单位
				this.$data.companyCombo = [];


				debugger;
				this.$http.get(this.API_ROOT + "/rbac/dept/all", {
					params: {
						area: this.$data.area,
						brand: this.$data.brand
					}
				}).then(resp => {
					this.$data.companyCombo = resp.data.dataList;
					if(this.$data.companyCombo.length > 0){
						this.$data.companyId = this.$data.companyCombo[0].id;
					}
				});
			},
			//获取区域
			getarea: function() {

				debugger;
				this.$http.get(this.API_ROOT + "/rbac/dept/area/all", {
					params: {

					}
				}).then(resp => {
					this.$data.areaCombo = resp.data.dataList;
				});
			},
			//获取品牌
			getBrand: function() {
				debugger;
				this.$http.get(this.API_ROOT + "/rbac/dept/brand/all", {
					params: {}
				}).then(resp => {
					this.$data.brandCombo = resp.data.dataList;
				});
			},
			//huoqu renyuan
			getPeople: function() {
				this.$data.lengthComboData = [];//清空人员
				this.$data.saId = "";
				//人员
				this.$http.get(this.API_ROOT + '/crm/config/userComBo', {
					params: {
						companyId: this.$data.companyId,
					}
				}).then((response) => {

					this.$data.lengthComboData = response.data;
				}, (response) => {
					// error callback
				});
			},
			//获取活动
			getactivity: function() {
				this.$data.activeCheck = "";
				this.$data.queryNameCombo = [];//清空活动
				//获取所属活动下拉
				this.$http.get(this.API_ROOT + '/crm/activity/combo', {
					params: {
						companyId: this.$data.companyId,
					}
				}).then((response) => {
					this.$data.queryNameCombo = response.data;
				}, (response) => {});
			},

		},
		created: function() {
			this.$http({
				method: 'GET',
				url: this.API_ROOT + '/rbac/login/btn', //url 输出 按照车牌号的 车牌号
				params: { //发送的参数
					resPath: "crm/campaign/couponManage", ////查询条件 按照输入的车牌号
				}
			}).then(function(resp) {
				var btnData = resp.data.dataList;

				var temp = {};

				for(var i = 0; i < btnData.length; i++) {

					var btnName = btnData[i].btnName;

					temp[btnName] = btnName;

				}

				Object.assign(this.$data.btnGroup, temp);
			}, function(error) {
				// error
			});

			this.levelCovert();
			this.getarea();
			this.getBrand();
			this.getCompanyInfo();

			//省份下拉
			this.$http.get(this.API_ROOT + '/base/dict/combo', {
				params: {
					group: "sjName"
				}
			}).then((response) => {
				this.$data.shengfenCombo = response.data;
			}, (response) => {});
			//大写字母下拉
			this.$http.get(this.API_ROOT + '/base/dict/combo', {
				params: {
					group: "dxzm"
				}
			}).then((response) => {
				this.$data.zimuCombo = response.data;
			}, (response) => {});
			//获取所属活动下拉
			this.$http.get(this.API_ROOT + '/crm/activity/combo', {
				params: {
					inUse: "1"
				}
			}).then((response) => {
				this.$data.nameCombo = response.data;
			}, (response) => {});

			//获取状态下拉
			this.$http.get(this.API_ROOT + '/base/dict/combo', {
				params: {
					group: "030101"
				}
			}).then((response) => {
				this.$data.statusCombo = response.data;
			}, (response) => {});



		},
		components: {
			Qrcode
		}
	}
</script>